﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using System.Data;

namespace DA
{
    public class ConnectData
    {
        private SqlDataAdapter da;
        private SqlCommand cmd;
        private SqlConnection cnn;
        private DataTable dt;

        string CnnString = @"Data Source=.\SQLEXPRESS;Initial Catalog=QLHS_12;Integrated Security=True";
        protected ConnectData()
        {
            cnn = new SqlConnection(CnnString);
        }

        protected DataTable LayDatatable(string sql)
        {
            da = new SqlDataAdapter(sql, cnn);
            dt = new DataTable();
            da.Fill(dt);
            return dt;
        }

        protected bool ExecuteNonQuery(string sql)
        {
            cmd = new SqlCommand(sql, cnn);
            if (cnn.State == ConnectionState.Closed)
                cnn.Open();
            int i = cmd.ExecuteNonQuery();
            if (cnn.State == ConnectionState.Open)
                cnn.Close();

            //if (i > 0)
            //    return true;
            //else
            //    return false;
            return i > 0;
        }
    }
}